
const app = getApp();
import CryptUtils from '../../utils/cryption/CryptoUtils';
// import AesUtil from '../../utils/cryption/AesUtil';
import * as rquestInfoUtils from '../../http/RequestInfoUtils';
import * as NetworkUtils from '../../http/NetworkUtils';
import Constants from '../../common/Constants';

// import SendMailPop from '../../templates/SendMailPop/SendMailPop';
import { $SendMailPop } from '../../components/CompRouter';

Page({
    data: {
    },

    onLoad: function (options) {
        //加解密
        // _testCrypt();

        // _testAESEnc();
        // testC();

        // let list = ["abc" ,"abc", "123", "123", "123", "123", "123", "123", "123", "123"];
        // let result = RemoveDuplicate(list);
        // UmfLog.log(result);
        // UmfLog.log(list);

        // let params = {
        //     code: "hahaha",
        //     assistId: "dfsdff",
        //     userId: "sdfsdfasdf",
        //     password: "111111"
        // };
        // NetworkUtils.buildRequest(Constants.Interfaces.FUNC_LOGIN, params, {
        //     doHttpSucess: (response)=> {
        //         UmfLog.log("dangban:::::");
        //         UmfLog.log(response);
        //     }
        // }).send();

    },

    onSubmit: function (ee) {

        $SendMailPop.showSendMailPop({
            onMailInput: (value)=> {
                UmfLog.log("onMailInput" + value);
            },
            onConfirm(e) {
                UmfLog.log('凭什么吃我的冰淇淋！')
            },
            onCancel(e) {
                UmfLog.log('谢谢你不吃之恩！')
            },
        });
    }
});

function testC() {
    UmfLog.log("testC============================================");
    var value = "123456";
    var publicKey = "-----BEGIN PUBLIC KEY-----MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDYyfEHrBtCvXkl31lGFGq7xFovIdp5fWFJJJfejzILxvvlfAM42X+lOhDKUHmcxEEZn8nExck7zAQeSSm93P79IgBFcnDpKtNNghL8idZOe77RpXFYrFTu74SLqMBGRK7f6NOGb4VbMOnX1rxTL6cqdVxc5E58CX77ICOePjTeUwIDAQAB-----END PUBLIC KEY-----";
    var result = CryptoUtils.rsaEncrypt(value, CaHelper.getTxPublicKey());
    UmfLog.log("明文:" + value);
    UmfLog.log("密文:" + result);
}

function testB(){
    UmfLog.log("testB============================================");
    var value = "123456";
    var publicKey = "B61249498A08A8BE92A42F5066BFAC2CFC35B62C4569052EBC8987B2D9453D287696F0DAC442DC876A760C738EF5C0A6C498962572F903BE273DC29E2A55312EE54416E11BE88471AE66427A660D3E3566A1F949A1377BE525FF7B1B3483A99DE4714AF0CFC9EBB8881EE0164580714B24F3F6D5347367ADC792C25589B2E2E1";
    ohdaveRsa.setMaxDigits(131);
    var key = new ohdaveRsa.RSAKeyPair("10001", "", publicKey);
    var result = ohdaveRsa.encryptedString(key, value, "PKCS1Padding");
    UmfLog.log("明文:" + value);
    UmfLog.log("密文:" + result);

}

function _testAESEnc() {
    // var iv = "F27D5C9927726BCEFE7510B1BDD3D137";
    // var salt = "3FF2EC019C627B945225DEBAD71A01B6985FE84C95A70EB132882F88C0A59A55";
    // var plainText = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy "
    //     + "eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed "
    //     + "diam voluptua. At vero eos et acc usam et justo duo dolores et ea "
    //     + "rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem "
    //     + "ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur "
    //     + "sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et "
    //     + "dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam "
    //     + "et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea "
    //     + "takimata sanctus est Lorem ipsum dolor sit amet.";
    // var keySize = 128;
    // var iterations = 1000;
    var passPhrase = "1234567891234567"// var passPhrase = "the quick brown fox jumps over the lazy dog";
    // var cipherText = "/AFfJyswH99yaf/Zr8aTr9gmnhkskf2VGW1iYe14nLzoF9SFF1u4b3N3ebZeiS7av12Q7D0"
    //     + "71BpaWVek7qBZ4Q+OaUbzIAVYswvi/y460ImSsEkI4f3eZeleA1EULjSbPqYT0cZyHy6B"
    //     + "+BO7z1FMZwqxDGfPZaO7TgPOpKsIp34FIzKxBk+2YjRpf3cOVCyMY/qRQC3nxuEbBYr8y"
    //     + "IBu0tBuN1vRxfUD9rsFkf0/CszQrnRh2UqfIzI5XU5dgkifoab4b2Qa6/O78+GcbwuUo+"
    //     + "LKYC2KrVsVU6YzFV9I9eLjonIShGe2w27BedxpCk/G5pBxQIKCoFna79TKflSQr8O1vYq"
    //     + "taha41BzHw1h1WaRDFOv8NO0sgn5uEsmMsWuw5EDqwDdbJ99VFKYPF3Rh8mNcwbIreUID"
    //     + "B6zGfecU9FPacGlGuYM7rxFMut6HMiDrXwsmYQkL5wQR8yoF7j78U6RJPuUosrYZEO/XG"
    //     + "5TMFUIPvuU/jP/bvUHk6INOP31RFNI6cG6qWrRtwCoGztRbC8GENA5zgnF95/c1I65ZCT"
    //     + "MJ6VB4cxD0eXMTW3Ky5qAtTv4B0Z0bn1hKFGxmlBnJF50JZ1ZGTaF2vTRTTUJTFo62v5Z"
    //     + "0bSzH45sjMd6QOZdATn+3KY8ekXJY8N7WCQvFZMCZWVaHqfspFBfYzaZWzB6SuwioUN5z"
    //     + "r5KCrLuLCUHJ6I+zT4Pj+Baa19YtkbQhMNcky0936/dDHYTvTSu/of4Jux7ze30+tFqzXsWZOGsABdV0byv+6q8XptJne61A/w==";

    // var passPhrase = CryptUtils.getPassPhrase(16);
    UmfLog.log("passPhrase: " + passPhrase);

    var encrypt = CryptUtils.aesEncrypt(passPhrase, "123456");

    UmfLog.log("encrypt: " + encrypt);

    var decrypt = CryptUtils.aesDecrypt(passPhrase, encrypt);


    UmfLog.log("decrypt: " + decrypt);

    //
    // var aesUtil = new AesUtil(keySize, iterations);
    // var encrypt = aesUtil.encrypt(salt, iv, passPhrase, "123456");
    //
    // UmfLog.log("encrypt: " + encrypt);
    //
    // var decrypt = aesUtil.decrypt(salt, iv, passPhrase, encrypt);
    //
    //
    // UmfLog.log("decrypt: " + decrypt);
    //
    //
    // let aesKey = cryptUtils.getAESKey(16);
    //
    // UmfLog.log("aesKey: " + aesKey);
    //
    // let encryptData = cryptUtils.aesEncrypt("1234567", aesKey);
    // UmfLog.log("encryptData : " + encryptData);
    //
    // let dec = cryptUtils.aesDecrypt(encryptData.toString(), aesKey);
    // UmfLog.log("dec : " + dec);
}

function RemoveDuplicate(list) {
    if (!list) {
        return [];
    }
    let filter = function (element, index, self) {
        return self.indexOf(element) === index;
    };
    return list.filter(filter);
}